package com.simons.common.utils.file.office;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.apache.commons.io.IOUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;

public class Excel2003 extends AbstractExcel{

	@Override
	public <T> List<T> read(File file, String[] fieldNames, Class<T> calss) throws IOException, InstantiationException, IllegalAccessException{
		return this.read(file, 0, fieldNames, calss);
	}
	
	@Override
	public <T> List<T> read(File file, int sheetAt, String[] fieldNames, Class<T> calss) throws IOException, InstantiationException, IllegalAccessException {
		return this.read(new FileInputStream(file), sheetAt, fieldNames, calss);
	}
	
	@Override
	public <T> List<T> read(InputStream input, int sheetAt, String[] fieldNames, Class<T> calzz)
			throws IOException, InstantiationException, IllegalAccessException {
        HSSFWorkbook hwb = new HSSFWorkbook(input);
        try{
        	return this.read(hwb, sheetAt, fieldNames, calzz);
        }finally{
        	IOUtils.closeQuietly(hwb);
        }
	}
	
	@Override
	public int getNumberOfSheets(File file) throws IOException {
		// 构造 XSSFWorkbook 对象，strPath 传入文件路径
		HSSFWorkbook hwb = null;
		try{
			hwb = new HSSFWorkbook(new FileInputStream(file));
			return hwb.getNumberOfSheets();
		}finally{
			IOUtils.closeQuietly(hwb);
		}
	}

	@Override
	public int getSheetBySheetName(File file,String SheetName) throws FileNotFoundException, IOException {
		
		// 构造 XSSFWorkbook 对象，strPath 传入文件路径
		return getSheetBySheetName(new FileInputStream(file), SheetName);
		
	}
	

	@Override
	public int getSheetBySheetName(InputStream input, String SheetName) throws FileNotFoundException, IOException {
		HSSFWorkbook hwb = null;
		try {
			hwb = new HSSFWorkbook(input);
			return hwb.getSheetIndex(SheetName);
		} finally {
			IOUtils.closeQuietly(hwb);
		}
	}

	@Override
	public <T> void write(OutputStream out, String sheetName, String[] fieldNames, String[] heards,
			Collection<T> dataList) throws NoSuchMethodException, SecurityException, IllegalAccessException,
			IllegalArgumentException, InvocationTargetException, IOException {
		// TODO Auto-generated method stub
		
	}

	@Override
	public <T> Workbook getSimpleWorkBook() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> SXSSFWorkbook writeToWorkBook(Workbook workbook, String sheetName, String[] fieldNames, String[] heards,
			Collection<T> dataList) throws NoSuchMethodException, SecurityException, IllegalAccessException,
			IllegalArgumentException, InvocationTargetException, IOException {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public <T> void writeByEnum(OutputStream out, String sheetName, String[] fieldNames, String[] heards,
			Collection<T> dataList, Map<String, Map<String, String>> enumMap) {
		// TODO Auto-generated method stub
		
	}

}
